﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ServiceModel;
using System.ServiceModel.Security;
using System.DirectoryServices;

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            
            //DirectoryEntry de = new DirectoryEntry();
            //de.Path = "LDAP://DC=fareast,DC=corp,DC=microsoft,DC=com";
            //de.AuthenticationType = AuthenticationTypes.ReadonlyServer;
            //DirectorySearcher deSearch = new DirectorySearcher();
            //deSearch.SearchRoot = de;
            //deSearch.Filter = "(&(objectClass=user)(objectCategory=person))";
            //deSearch.PropertiesToLoad.Add(SystemUserEntity.ADProperties.samaccountname.ToString());
            //deSearch.PropertiesToLoad.Add(SystemUserEntity.ADProperties.displayname.ToString());
            //deSearch.ServerTimeLimit = new TimeSpan(0, 0, 60);
            //deSearch.SizeLimit = 100;
            //SearchResultCollection results = deSearch.FindAll();

            //foreach (SearchResult result in results)
            //{
            //    System.Diagnostics.Debug.WriteLine(string.Format("Display Name = {0} / Alias = {1}", result.GetADProperty(SystemUserEntity.ADProperties.displayname.ToString()), result.GetADProperty(SystemUserEntity.ADProperties.samaccountname.ToString())));
            //}

            string time = "";
            var ServiceendPoint = new EndpointAddress(new Uri("http://localhost/AuthService/Service1.svc"), EndpointIdentity.CreateDnsIdentity("MyWebSite"));
            var binding = new WSHttpBinding();
            binding.Security.Mode = SecurityMode.Message;
            binding.Security.Message.ClientCredentialType = MessageCredentialType.UserName;


            var result = new ServiceReference1.Service1Client(binding, ServiceendPoint);
            result.ClientCredentials.ServiceCertificate.Authentication.CertificateValidationMode = X509CertificateValidationMode.None;
            result.ClientCredentials.UserName.UserName = "vipul";
            result.ClientCredentials.UserName.Password = "mehta";
            time = result.GetServertime();
            Console.WriteLine(time);
            Console.ReadLine();
        }
    }
}
